#include "DataProcessor.h"

DataProcessor::DataProcessor(QObject* parent) : QObject(parent),running(false)
{
    // 将当前对象移动到线程中
    this->moveToThread(&workerThread);

    //线程启动后调用函数
    connect(&workerThread, &QThread::started, this, &DataProcessor::Process);

    workerThread.start();
}

DataProcessor::~DataProcessor()
{
    stop();
    workerThread.quit();
    workerThread.wait();
}

void DataProcessor::start()
{
    running = true;
}

void DataProcessor::stop()
{
    running = false;
}


void DataProcessor::Process()
{
    running = true;
    while (running)
    {
        QThread::msleep(100); // 模拟数据接收间隔

        // 模拟接收到的数据
        QByteArray data("Hello Qt Thread");
        emit dataReceived(data);
    }
}
